package com.hobbit.utils
{
	import flash.external.ExternalInterface;

	/**
	 * 浏览器工具 -->判断运行的是何种浏览器、获取浏览器信息等
	 * @author 晓晔
	 *  
	 */
	public class Browser
	{
		
		public static const IE:String = "ie";
		public static const MOZ:String = "moz";
		public static const SAFARI:String = "safari";
		public static const OPERA:String = "opera";
		public static const CHROME:String = "chrome";
		
		/**
		 * 判断是否是当前浏览器 
		 * @param $browserName 浏览器名称
		 * @return 
		 * 
		 */
		public static function checkBrowser($browserName:String):Boolean
		{
			var b:Boolean;
			var tempType:String;
			switch($browserName)
			{
				case IE:
					tempType = "msie";
					break;
				case MOZ:
					tempType = "gecko";
					break;
				case SAFARI:
					tempType = "safari";
					break;
				case OPERA:
					tempType = "opera";
					break;
				case CHROME:
					tempType = "chrome"
					break;
				default:
					return false;
			}
			try
			{
				b = ExternalInterface.call(
					"function isBrow(){return /"+tempType+"/.test(navigator.userAgent.toLowerCase());}");
			} 
			catch(error:Error) 
			{
				trace("Browser--->error.checkBrowser");
				b = false;
			}
			return b;
		}
		
		/**
		 * 获取浏览器信息
		 * @return 
		 * 
		 */
		public static function getBrowserInfo():String
		{
			var info:String;
			try
			{
				info = ExternalInterface.call(
					"function BrowserAgent(){return navigator.userAgent;}");
			} 
			catch(error:Error) 
			{
				trace("Browser--->error.getBrowserInfo");
				info = "";
			}
			
			return info;
		}
		
		/**
		 * 获取当前url路径
		 * @return 
		 * 
		 */
		public static function getBrowserUrl():String
		{
			var bUrl:String 
			
			try
			{
				bUrl = ExternalInterface.call(
					"function getUrl(){return document.location.href;}");
			} 
			catch(error:Error) 
			{
				trace("Browser--->error.getBrowserUrl");
				bUrl = "";
			}
			
			return bUrl;
		}
		
	}
}